package com.example.demo2.controller;

import com.example.demo2.generator.entity.CarList;
import com.example.demo2.generator.entity.R;
import com.example.demo2.generator.entity.WlManager;
import com.example.demo2.generator.service.CarListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆列表(CarList)表控制层
 *
 * @author makejava
 * @since 2024-09-18 11:28:07
 */
@RestController
@RequestMapping("/carList")
@Api(value = "汽车列表Controller",tags = "汽车列表接口")
public class CarListController {
    /**
     * 服务对象
     */
    @Resource
    private CarListService carListService;
    @ApiOperation("查询所有汽车信息")
    @RequestMapping(value = "/queryAllCarList",method = RequestMethod.POST)
    public R queryAllCarList(){
        List<CarList> carLists = carListService.queryAllCarList();
        int count=carLists.size();
        return R.ok(count,"查询成功",carLists);
    }
    @ApiOperation("模糊查询")
    @RequestMapping(value = "/queryCarListLimit",method = RequestMethod.POST)
    public R queryCarListLimit(CarList carList){
        System.out.println(carList.toString()+"...........................");
        List<CarList> carLists = carListService.queryAllByLimit(carList);
        int count=carLists.size();
        return R.ok(count,"查询成功",carLists);
    }
    @ApiOperation("添加汽车信息")
    @RequestMapping("/addCarList")
    public R addCarList(@RequestBody CarList carList){
        System.out.println("===执行添加汽车列表操作===");
        System.out.println(carList+".................");
        CarList carlist = carListService.insert(carList);
        return R.ok("添加成功",carlist);
    }


    /**
     * 删除数据
     *
     * @param carListId 主键
     * @return 删除是否成功
     */
    @ApiOperation("删除单个汽车列表")
    @PostMapping("/deleteById")
    public R deleteById(Integer carListId) {
        boolean b = this.carListService.deleteById(carListId);
        return R.ok("删除成功");
    }
    @ApiOperation("批量删除货物")
    @PostMapping("/deletes")
    public R deletes(@RequestBody List<CarList>carLists) {
        int deletes = carListService.deleteBatch(carLists);
        return R.ok( deletes,"批量删除成功删除",null);
    }
    @ApiOperation("更新汽车列表")
    @PostMapping("/updateCarList")
    public R updateCarList(@RequestBody CarList carList) {
        CarList update = this.carListService.update(carList);
        return R.ok("更新成功",update);
    }

}

